<template>
  <div>
  <div class="page-login" v-if="false">
    <div class="page-login--layer page-login--layer-area">
      <ul class="circles">
        <li v-for="n in 10" :key="n"></li>
      </ul>
    </div>
    <div
      class="page-login--layer page-login--layer-time"
      flex="main:center cross:center">
      {{time}}
    </div>
    <div class="page-login--layer">
      <div
        class="page-login--content"
        flex="dir:top main:justify cross:center box:justify">
        <div class="page-login--content-header">
          <p class="page-login--content-header-motto">
            时间是一切财富中最宝贵的财富。 <span>—— 德奥弗拉斯多</span>
          </p>
        </div>
        <div
          class="page-login--content-main"
          flex="dir:top main:center cross:center">
          <!-- logo -->
          <img class="page-login--logo" src="./image/logo@2x.png">
          <!-- 表单 -->
          <div class="page-login--form">
            <el-card shadow="never">
              <el-form ref="loginForm" label-position="top" :rules="rules" :model="formLogin" size="default">
                <el-form-item prop="username">
                  <el-input type="text" v-model="formLogin.username" placeholder="用户名">
                    <i slot="prepend" class="fa fa-user-circle-o"></i>
                  </el-input>
                </el-form-item>
                <el-form-item prop="password">
                  <el-input type="password" v-model="formLogin.password" placeholder="密码">
                    <i slot="prepend" class="fa fa-keyboard-o"></i>
                  </el-input>
                </el-form-item>
                <el-form-item prop="code">
                  <el-input type="text" v-model="formLogin.code" placeholder="- - - -">
                    <template slot="prepend">验证码</template>
                    <template slot="append">
                      <img class="login-code" src="./image/login-code.png">
                    </template>
                  </el-input>
                </el-form-item>
                <el-button size="default" @click="submit" type="primary" class="button-login">登录</el-button>
              </el-form>
            </el-card>
            <p
              class="page-login--options"
              flex="main:justify cross:center">
              <span><d2-icon name="question-circle"/> 忘记密码</span>
              <span>注册用户</span>
            </p>
            <!-- 快速登录按钮 -->
            <el-button class="page-login--quick" size="default" type="info" @click="dialogVisible = true">
              快速选择用户（测试功能）
            </el-button>
          </div>
        </div>
        <div class="page-login--content-footer">
          <p class="page-login--content-footer-options">
            <a href="#">帮助</a>
            <a href="#">隐私</a>
            <a href="#">条款</a>
          </p>
          <p class="page-login--content-footer-copyright">
            Copyright <d2-icon name="copyright"/> 2018 D2 Projects 开源组织出品 <a href="https://github.com/FairyEver">@FairyEver</a>
          </p>
        </div>
      </div>
    </div>
    <el-dialog
      title="快速选择用户"
      :visible.sync="dialogVisible"
      width="400px">
      <el-row :gutter="10" style="margin: -20px 0px -10px 0px;">
        <el-col v-for="(user, index) in users" :key="index" :span="8">
          <div class="page-login--quick-user" @click="handleUserBtnClick(user)">
            <d2-icon name="user-circle-o"/>
            <span>{{user.name}}</span>
          </div>
        </el-col>
      </el-row>
    </el-dialog>
  </div>

  <div class="login-wrapper">
    <div class="loader" style="display:none">
      <div class="la-ball-clip-rotate">
        <div></div>
      </div>
    </div>
    <div class="system-login" style="background-image: url('./image/bg-login.png');height: 900px;">
      <div class="head">
        <a href="/" class="logo-version">
          <img src="./image/logo.png" class="logo">
          <span class="version hidden">1.0</span>
        </a>
      </div>
      <el-form ref="loginForm" label-position="top" :rules="rules" :model="formLogin" size="default">
        <div class="login-panel">
          <div class="title">
            <a href="javascript:void(0);">账号/手机登录</a>
          </div>
          <!--<form action="" method="post" role="form" id="form1" onsubmit="return formcheck();" class="we7-form">-->
          <div class="input-group-vertical">
             <el-form-item prop="username">
              <el-input type="text" v-model="formLogin.username" placeholder="请输入用户名/手机登录"></el-input>
            </el-form-item>
            <!--<input name="login_type" type="hidden" class="form-control " value="system">-->
            <!--<input name="username" type="text" class="form-control " placeholder="请输入用户名/手机登录">-->
            <el-form-item prop="password">
              <el-input type="password" v-model="formLogin.password" class="password" placeholder="请输入登录密码"></el-input>
            </el-form-item>
            <!--<input name="password" type="password" class="form-control password" placeholder="请输入登录密码">-->
          </div>

          <div class="form-inline" style="margin-bottom: 15px;">
            <div class="checkbox">
              <input type="checkbox" value="true" id="rember" name="rember">
              <label for="rember">记住用户名</label>
            </div>
          </div>
          <div class="login-submit text-center">
             <!--<el-button size="default" @click="submit" type="primary" class="button-login">登录</el-button>-->
            <button id="submit" name="submit" class="btn btn-primary btn-block" @click="submit">登录</button>
            <input name="token" value="" type="hidden"/>
          </div>
          <!--</form>-->
        </div>
      </el-form>
    </div>
    <div class="footer">
      <p class="maincontent">典则读书</p>
      <p class="subcontent">典则读书@2019</p>
    </div>
  </div>
</div>
</template>
<style scoped>
  .login-wrapper {
    overflow-y: hidden;
  }
  .footer {
    text-align: center;
  }
  .footer .maincontent {
    font-size: 16px;
  }
  .footer .subcontent {
     color: #ccc;
     font-size:12px;
  }
  .loader {
    position: fixed;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    z-index: 9999;
    background: #000 50% 50%;
    opacity: .3
  }

  .la-ball-clip-rotate,
  .la-ball-clip-rotate>div {
    position: relative;
    left: 50%;
    top: 50%;
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box
  }

  .la-ball-clip-rotate {
    display: block;
    font-size: 0;
    color: #428bca;
    width: 64px;
    height: 64px
  }

  .la-ball-clip-rotate>div {
    display: inline-block;
    float: none;
    background-color: currentColor;
    border: 0 solid currentColor;
    width: 64px;
    height: 64px;
    border-width: 4px;
    background: 0 0;
    border-bottom-color: transparent;
    border-radius: 100%;
    -webkit-animation: ball-clip-rotate .5s linear infinite;
    -moz-animation: ball-clip-rotate .5s linear infinite;
    -o-animation: ball-clip-rotate .5s linear infinite;
    animation: ball-clip-rotate .5s linear infinite
  }

  .register {
    width: 960px;
    margin: 0 auto
  }

  .register .panel-body {
    padding: 30px
  }

  .register .login-submit {
    margin-top: 50px
  }

  .login .panel,
  .register .panel {
    border-radius: 6px 6px 0 0
  }

  .login .panel .input-group-addon,
  .register .panel .input-group-addon {
    background-color: #fff;
    border-color: #e7e7eb;
    border-right: 0
  }

  .login .panel .input-group-addon+input,
  .register .panel .input-group-addon+input {
    border-left: 0
  }

  .login-panel .title,
  .register .title {
    text-align: center;
    font-size: 16px;
    color: #1a1a1a;
    margin-bottom: 30px;
    border-bottom: 1px solid #e7e7eb
  }

  .login-panel .title a,
  .register .title a {
    color: black;
    display: inline-block;
    padding: 10px 20px;
    border-bottom: 2px solid transparent
  }

  .login-panel .title a.active,
  .login-panel .title .panel-menu a.list-group-item:not(.list-group-more):hover,
  .panel-menu .login-panel .title a.list-group-item:not(.list-group-more):hover,
  .register .title a.active,
  .register .title .panel-menu a.list-group-item:not(.list-group-more):hover,
  .panel-menu .register .title a.list-group-item:not(.list-group-more):hover {
    border-color: #428bca
  }

  .login-submit .btn {
    height: 38px;
    line-height: 24px;
    font-size: 16px;
    margin-bottom: 15px;
    color: #fff;
    background-color: #428bca;
    border-color: #357ebd;
    width: 100%;
  }

  .system-login,
  .system-register {
    width: 100%;
    background-size: cover;
    background-position: 50% 50%
  }

  .system-login .head,
  .system-register .head {
    line-height: 50px;
    padding: 0 30px;
    overflow: hidden;
    background: rgba(255, 255, 255, .2)
  }

  .system-login .head .logo-version,
  .system-register .head .logo-version {
    display: inline-block;
    height: 50px
  }

  .system-login .head .logo,
  .system-register .head .logo {
    width: auto;
    height: 35px
  }

  .system-login .head .version,
  .system-register .head .version {
    margin-left: 6px;
    margin-top: 7px;
    background-color: #aeaeae;
    padding: 2px 5px;
    display: block;
    float: right;
    border-radius: 2px;
    color: #fff;
    line-height: 1
  }

  .system-login .head .pull-right,
  .system-register .head .pull-right {
    color: #fff;
    font-size: 16px
  }

  .system-login .head {
    display: table;
    width: 100%;
  }
  .system-login .head a {
    display: table-cell;
  }
  .system-login .head a img {
    margin-bottom: -12px;
  }

  .system-login .login-panel,
  .system-register .login-panel {
    width: 300px
  }

  .system-login .register-panel,
  .system-register .register-panel {
    width: 460px;
    max-height: 605px;
    overflow-y: auto
  }

  .system-login .register-panel .input-group-btn .btn,
  .system-register .register-panel .input-group-btn .btn {
    height: 40px
  }

  .system-login+.footer,
  .system-register+.footer {
    position: fixed;
    width: 100%;
    bottom: 0;
    left: 0;
    color: #666;
    background-color: #fff
  }

  .system-login+.footer .friend-link,
  .system-register+.footer .friend-link {
    font-size: 16px
  }

  .system-login+.footer .friend-link a,
  .system-register+.footer .friend-link a {
    padding: 0 30px
  }

  .system-login+.footer .friend-link a+a,
  .system-register+.footer .friend-link a+a {
    border-left: 1px solid #ccc
  }

  .system-login+.footer .copyright,
  .system-register+.footer .copyright {
    color: #ccc;
    margin-top: 20px
  }

  .login-panel,
  .register-panel {
    padding: 0 20px 30px 20px;
    background: rgba(255, 255, 255, .7);
    border-radius: 4px;
    position: fixed;
    right: 20%;
    top: 20%
  }

  .login-panel .input-group-vertical input,
  .register-panel .input-group-vertical input {
    height: 40px;
    border-radius: 4px;
    box-sizing: border-box;
  }

  .login-panel .input-group-vertical>input,
  .register-panel .input-group-vertical>input {
    margin-bottom: 15px
  }

  .login-panel .input-group-vertical .input-group,
  .register-panel .input-group-vertical .input-group {
    margin-bottom: 15px
  }

  .login-panel .input-group-vertical .input-group input,
  .register-panel .input-group-vertical .input-group input {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0
  }

  .login-panel .input-group-vertical .imgverify,
  .register-panel .input-group-vertical .imgverify {
    border-top-right-radius: 4px;
    border-bottom-right-radius: 4px
  }

  @-webkit-keyframes ball-clip-rotate {
    0% {
      -webkit-transform: rotate(0deg);
      transform: rotate(0deg)
    }
    50% {
      -webkit-transform: rotate(180deg);
      transform: rotate(180deg)
    }
    100% {
      -webkit-transform: rotate(360deg);
      transform: rotate(360deg)
    }
  }

  @-moz-keyframes ball-clip-rotate {
    0% {
      -moz-transform: rotate(0deg);
      transform: rotate(0deg)
    }
    50% {
      -moz-transform: rotate(180deg);
      transform: rotate(180deg)
    }
    100% {
      -moz-transform: rotate(360deg);
      transform: rotate(360deg)
    }
  }

  @-o-keyframes ball-clip-rotate {
    0% {
      -o-transform: rotate(0deg);
      transform: rotate(0deg)
    }
    50% {
      -o-transform: rotate(180deg);
      transform: rotate(180deg)
    }
    100% {
      -o-transform: rotate(360deg);
      transform: rotate(360deg)
    }
  }

  @keyframes ball-clip-rotate {
    0% {
      -webkit-transform: rotate(0deg);
      -moz-transform: rotate(0deg);
      -o-transform: rotate(0deg);
      transform: rotate(0deg)
    }
    50% {
      -webkit-transform: rotate(180deg);
      -moz-transform: rotate(180deg);
      -o-transform: rotate(180deg);
      transform: rotate(180deg)
    }
    100% {
      -webkit-transform: rotate(360deg);
      -moz-transform: rotate(360deg);
      -o-transform: rotate(360deg);
      transform: rotate(360deg)
    }
  }

  .we7-form .form-group,
  form .form-group {
    margin-bottom: 30px
  }

  .we7-form .form-group:before,
  form .form-group:before {
    content: '';
    display: table
  }

  .we7-form .form-group:after,
  form .form-group:after {
    display: table;
    clear: both;
    content: ''
  }

  .we7-form .control-label,
  form .control-label {
    padding-top: 7px;
    padding-left: 0;
    padding-right: 0;
    text-align: left;
    color: #252424;
    font-weight: 400
  }

  .we7-form .form-controls,
  form .form-controls {
    padding-left: 0;
    padding-right: 0
  }

  .we7-form .form-control,
  form .form-control {
    border-color: #e7e7eb;
    border-radius: 0;
    box-shadow: 0 0 0;
    text-shadow: 0 0 0
  }

  .we7-form .help-block,
  form .help-block {
    color: #98999a;
    padding-top: 10px;
    margin-top: 0;
    margin-bottom: 0
  }

  .we7-form .checkbox-block input[type=radio]+label,
  .we7-form .checkbox-block input[type=checkbox]+label,
  .we7-form .radio-block input[type=radio]+label,
  .we7-form .radio-block input[type=checkbox]+label,
  form .checkbox-block input[type=radio]+label,
  form .checkbox-block input[type=checkbox]+label,
  form .radio-block input[type=radio]+label,
  form .radio-block input[type=checkbox]+label {
    display: block
  }

  .we7-form label,
  form label {
    color: #252424;
    font-weight: 400;
    vertical-align: middle;
    margin-bottom: 0
  }
  .form-control {
    display: block;
    width: 100%;
    height: 34px;
    padding: 6px 12px;
    font-size: 14px;
    line-height: 1.42857143;
    color: #555;
    background-color: #fff;
    background-image: none;
    border: 1px solid #ccc;
    border-radius: 4px;
    -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075);
    box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075);
    -webkit-transition: border-color ease-in-out .15s, -webkit-box-shadow ease-in-out .15s;
    -o-transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s;
    transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s
  }

  .form-control:focus {
    border-color: #66afe9;
    outline: 0;
    -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075), 0 0 8px rgba(102, 175, 233, .6);
    box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075), 0 0 8px rgba(102, 175, 233, .6)
  }

  .form-control::-moz-placeholder {
    color: #999;
    opacity: 1
  }

  .form-control:-ms-input-placeholder {
    color: #999
  }

  .form-control::-webkit-input-placeholder {
    color: #999
  }

  .form-control[disabled],
  .form-control[readonly],
  fieldset[disabled] .form-control {
    cursor: not-allowed;
    background-color: #eee;
    opacity: 1
  }
  .footer {
    position: fixed;
    width: 100%;
    bottom: 0;
    left: 0;
    color: #666;
    background-color: #fff;
  }
</style>
<script>
import dayjs from 'dayjs'
import { mapActions } from 'vuex'
export default {
  data () {
    return {
      timeInterval: null,
      time: dayjs().format('HH:mm:ss'),
      // 快速选择用户
      dialogVisible: false,
      users: [
        {
          name: '管理员',
          username: 'admin',
          password: 'admin'
        },
        {
          name: '编辑',
          username: 'editor',
          password: 'editor'
        },
        {
          name: '用户1',
          username: 'user1',
          password: 'user1'
        }
      ],
      // 表单
      formLogin: {
        username: 'admin',
        password: 'admin',
        code: 'v9am'
      },
      // 校验
      rules: {
        username: [
          { required: true, message: '请输入用户名', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' }
        ],
        code: [
          { required: true, message: '请输入验证码', trigger: 'blur' }
        ]
      }
    }
  },
  mounted () {
    this.timeInterval = setInterval(() => {
      this.refreshTime()
    }, 1000)
  },
  beforeDestroy () {
    clearInterval(this.timeInterval)
  },
  methods: {
    ...mapActions('d2admin/account', [
      'login'
    ]),
    refreshTime () {
      this.time = dayjs().format('HH:mm:ss')
    },
    /**
     * @description 接收选择一个用户快速登录的事件
     * @param {Object} user 用户信息
     */
    handleUserBtnClick (user) {
      this.formLogin.username = user.username
      this.formLogin.password = user.password
      this.submit()
    },
    /**
     * @description 提交表单
     */
    // 提交登录信息
    submit () {
      this.$refs.loginForm.validate((valid) => {
        console.log('校验结果为：', valid)
        if (valid) {
          // 登录
          // 注意 这里的演示没有传验证码
          // 具体需要传递的数据请自行修改代码
          this.login({
            vm: this,
            username: this.formLogin.username,
            password: this.formLogin.password
          })
            .then(() => {
              console.log('login成功，进行跳转')
              // 重定向对象不存在则返回顶层路径
              this.$router.replace(this.$route.query.redirect || '/')
            })
        } else {
          // 登录表单校验失败
          this.$message.error('表单校验失败')
        }
      })
    }
  }
}
</script>

<style lang="scss">
.page-login {
  @extend %unable-select;
  $backgroundColor: #F0F2F5;
  // ---
  background-color: $backgroundColor;
  height: 100%;
  position: relative;
  // 层
  .page-login--layer {
    @extend %full;
    overflow: auto;
  }
  .page-login--layer-area {
    overflow: hidden;
  }
  // 时间
  .page-login--layer-time {
    font-size: 24em;
    font-weight: bold;
    color: rgba(0, 0, 0, 0.03);
    overflow: hidden;
  }
  // 登陆页面控件的容器
  .page-login--content {
    height: 100%;
    min-height: 500px;
  }
  // header
  .page-login--content-header {
    padding: 1em 0;
    .page-login--content-header-motto {
      margin: 0px;
      padding: 0px;
      color: $color-text-normal;
      text-align: center;
      font-size: 12px;
      span {
        color: $color-text-sub;
      }
    }
  }
  // main
  .page-login--logo {
    width: 240px;
    margin-bottom: 2em;
    margin-top: -2em;
  }
  // 登录表单
  .page-login--form {
    width: 280px;
    // 卡片
    .el-card {
      margin-bottom: 15px;
    }
    // 登录按钮
    .button-login {
      width: 100%;
    }
    // 输入框左边的图表区域缩窄
    .el-input-group__prepend {
      padding: 0px 14px;
    }
    .login-code {
      height: 40px - 2px;
      display: block;
      margin: 0px -20px;
      border-top-right-radius: 2px;
      border-bottom-right-radius: 2px;
    }
    // 登陆选项
    .page-login--options {
      margin: 0px;
      padding: 0px;
      font-size: 14px;
      color: $color-primary;
      margin-bottom: 15px;
      font-weight: bold;
    }
    .page-login--quick {
      width: 100%;
    }
  }
  // 快速选择用户面板
  .page-login--quick-user {
    @extend %flex-center-col;
    padding: 10px 0px;
    border-radius: 4px;
    &:hover {
      background-color: $color-bg;
      i {
        color: $color-text-normal;
      }
      span {
        color: $color-text-normal;
      }
    }
    i {
      font-size: 36px;
      color: $color-text-sub;
    }
    span {
      font-size: 12px;
      margin-top: 10px;
      color: $color-text-sub;
    }
  }
  // footer
  .page-login--content-footer {
    padding: 1em 0;
    .page-login--content-footer-options {
      padding: 0px;
      margin: 0px;
      margin-bottom: 10px;
      font-size: 14px;
      text-align: center;
      a {
        color: $color-text-normal;
        margin: 0 1em;
      }
    }
    .page-login--content-footer-copyright {
      padding: 0px;
      margin: 0px;
      font-size: 12px;
      color: $color-text-normal;
      a {
        color: $color-text-normal;
      }
    }
  }
  // 背景
  .circles {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    li {
      position: absolute;
      display: block;
      list-style: none;
      width: 20px;
      height: 20px;
      background: #FFF;
      animation: animate 25s linear infinite;
      bottom: -200px;
      @keyframes animate {
        0%{
          transform: translateY(0) rotate(0deg);
          opacity: 1;
          border-radius: 0;
        }
        100%{
          transform: translateY(-1000px) rotate(720deg);
          opacity: 0;
          border-radius: 50%;
        }
      }
      &:nth-child(1) {
        left: 15%;
        width: 80px;
        height: 80px;
        animation-delay: 0s;
      }
      &:nth-child(2) {
        left: 5%;
        width: 20px;
        height: 20px;
        animation-delay: 2s;
        animation-duration: 12s;
      }
      &:nth-child(3) {
        left: 70%;
        width: 20px;
        height: 20px;
        animation-delay: 4s;
      }
      &:nth-child(4) {
        left: 40%;
        width: 60px;
        height: 60px;
        animation-delay: 0s;
        animation-duration: 18s;
      }
      &:nth-child(5) {
        left: 65%;
        width: 20px;
        height: 20px;
        animation-delay: 0s;
      }
      &:nth-child(6) {
        left: 75%;
        width: 150px;
        height: 150px;
        animation-delay: 3s;
      }
      &:nth-child(7) {
        left: 35%;
        width: 200px;
        height: 200px;
        animation-delay: 7s;
      }
      &:nth-child(8) {
        left: 50%;
        width: 25px;
        height: 25px;
        animation-delay: 15s;
        animation-duration: 45s;
      }
      &:nth-child(9) {
        left: 20%;
        width: 15px;
        height: 15px;
        animation-delay: 2s;
        animation-duration: 35s;
      }
      &:nth-child(10) {
        left: 85%;
        width: 150px;
        height: 150px;
        animation-delay: 0s;
        animation-duration: 11s;
      }
    }
  }
}
</style>
